/**
 * +======================================================================================================================+
 * @Author: CimZzz
 * @Date: 2022-09-13 11:24:06
 * 
 * 代码分割块，以下内容涉及: 
 * 
 * 针对消息队列线程注册类型回调的测试用例
 * 
 */
#include <cstdio>
#include "vl_message_queue.h"

using namespace VL;

void handleNumber1Callback(const std::shared_ptr<VLMessageQueueData>& dataPtr) {
	printf("recv number 1 msg : %d\n", *dataPtr->memoryCast<int>());
}
void handleNumber2Callback(const int& data) {
	printf("recv number 2 msg : %d\n", data);
}
void handleNumber3Callback(const int* data, unsigned int syncCode) {
	printf("recv number 3 msg : %d, %d\n", *data, syncCode);
}
void handleNumber4Callback(const std::shared_ptr<int>& dataPtr) {
	printf("recv number 4 msg : %d\n", *dataPtr);
}

int main(int argc, char** argv) {
	VLMessageQueueThread msgThread;
	msgThread.registerTypeCallback(1, handleNumber1Callback);
	msgThread.registerTypeCallback<int>(2, handleNumber2Callback);
	msgThread.registerTypeSyncCallback<int>(3, handleNumber3Callback);
	msgThread.registerTypeCallback<int>(4, handleNumber4Callback);

	bool isRunning = true;
	while(isRunning) {
		char c = getchar();
		switch(c) {
			case 's':
				msgThread.loop();
				break;
			case 'a':
				msgThread.enqueue(1, 1);
				break;
			case 'b':
				msgThread.enqueue(2, 2);
				break;
			case 'c':
				msgThread.enqueue(3, 3);
				break;
			case 'd':
				msgThread.enqueue(4, 4);
				break;
			case 'e':
				msgThread.destroy();
				break;
			case 'q':
				// 停止循环
				isRunning = false;
				break;
		}
	}


	return 0;
}